/**
 * @Author：ming
 * @Date：2023/10/1 1:42 AM
 * @Filename：Lc238
 */

/**
 * @author ming
 */
public class Lc238 {
    public int[] productExceptSelf(int[] nums) {

        int len = nums.length;
        int[] l = new int[len];
        int[] r = new int[len];
        int[] a = new int[len];
        for (int i = 0; i < len; i++) {
            if(i==1){
                l[i]=1;
            }else {
                l[i] = l[i-1]*nums[i-1];
            }

        }

        for (int i = len-1; i >=0 ; i++) {
            if(i==len-1){
                r[len-1]=1;
            }else {
                r[i]=r[i+1]*nums[i+1];
            }
        }

        for (int i = 0; i < len; i++) {
            a[i]=l[i]*r[i];
        }

        return a;


    }
}
